package com.zb.kl.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(
        value = "API 响应体",
        description = "API 响应体"
)
public class APIResponse<T> {
    @ApiModelProperty("响应码 0: 成功; 1: 失败")
    private Integer code;
    private Boolean success;
    private Boolean failed;
    @ApiModelProperty("响应信息")
    private String msg;
    @ApiModelProperty("响应数据")
    private T data;
    public APIResponse() {
    }

    public APIResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> APIResponse<T> success() {
        return success(null);
    }

    public static <T> APIResponse<T> success(T data) {
        return success(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getZhMsg(), data);
    }

    public static <T> APIResponse<T> success(Integer code, String msg) {
        return success(code, msg, null);
    }

    public static <T> APIResponse<T> success(Integer code, String msg, T data) {
        return new APIResponse(code, msg, data);
    }

    public static <T> APIResponse<T> failure() {
        return failure(ResponseCode.FAILED.getCode(), ResponseCode.FAILED.getZhMsg());
    }

    public static <T> APIResponse<T> failure(Integer code, String msg) {
        return failure(code, msg, null);
    }

    public static <T> APIResponse<T> failure(Integer code, String msg, T data) {
        return new APIResponse(code, msg, data);
    }

    public Integer getCode() {
        return this.code;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public void setFailed(Boolean failed) {
        this.failed = failed;
    }

    public String getMsg() {
        return this.msg;
    }

    public Boolean getSuccess() {
        return this.success;
    }

    public Boolean getFailed() {
        return this.failed;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String toString() {
        return "APIResponse(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }

}

